<?php

namespace app\controller\main;

use linkphp\Application;

class Register
{

    public function __construct()
    {
        Application::singletonEager(
            'register',
            'app\\logic\\main\\Register'
        );
        Application::singletonEager(
            'registerData',
            'app\\model\\main\\Register'
        );
    }

    public function register()
    {
        if(!Application::httpRequest()->isPost()){
            return ['code' => 2, 'msg' => '非法提交!'];
        }
        if(Application::input('post.account') == ''){
            return ['code' => 2, 'msg' => '账号不能为空!'];
        }
        if(Application::input('post.password') == ''){
            return ['code' => 2, 'msg' => '密码不能为空!'];
        }
        if(Application::input('post.password2') == ''){
            return ['code' => 2, 'msg' => '密码不能为空!'];
        }
        if(Application::get('register')->register()){
            return ['code' => 1, 'msg' => '注册成功'];
        } else {
            return ['code' => 2, 'msg' => '注册失败!'];
        }
    }

}